// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ClientHandlerObjectFactory.java

package org.quickserver.util.pool;

import org.apache.commons.pool.BasePoolableObjectFactory;
import org.quickserver.net.server.ClientHandler;
import org.quickserver.net.server.impl.*;

public class ClientHandlerObjectFactory extends BasePoolableObjectFactory
{

    public ClientHandlerObjectFactory(boolean blocking)
    {
        id = -1;
        this.blocking = true;
        id = ++instanceCount;
        this.blocking = blocking;
    }

    public Object makeObject()
    {
        if(blocking)
            return new BlockingClientHandler(id);
        else
            return new NonBlockingClientHandler(id);
    }

    public void passivateObject(Object obj)
    {
        ClientHandler ch = (ClientHandler)obj;
        ch.clean();
    }

    public void activateObject(Object obj1)
    {
    }

    public void destroyObject(Object obj)
    {
        if(obj == null)
        {
            return;
        } else
        {
            passivateObject(obj);
            obj = null;
            return;
        }
    }

    public boolean validateObject(Object obj)
    {
        if(obj == null)
            return false;
        BasicClientHandler ch = (BasicClientHandler)obj;
        return ch.getInstanceCount() == id;
    }

    private static int instanceCount = 0;
    private int id;
    private boolean blocking;

}
